<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>比赛战队</title>
    <meta content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0" name="viewport" />
    <meta content="yes" name="apple-mobile-web-app-capable" />
    <meta content="black" name="apple-mobile-web-app-status-bar-style" />
    <meta content="telephone=no" name="format-detection" />

    <link rel="stylesheet" href="css/demo.css" />
    <script src="js/ydui.flexible.js"></script>
</head>

<body>
    <section class="g-flexview" id="app" v-cloak>
        <section class="g-scrollview">

            <div class="m-cell">
                <label class="cell-item" v-for="item in teamlist">
                    <span class="cell-left">{{item.label1}}</span>
                    <label class="cell-right">
                        <input   :value="item.value" v-model="checkedId"  type="checkbox" />
                        <i class="cell-checkbox-icon"></i>
                    </label>
                </label>
            </div>
            <div class="m-button">
                <button type="button" id="saveBtn" @click="saveBtn" class="btn-block btn-primary">保存</button>
            </div>
        </section>
    </section>
    <script src="js/jquery.min.js"></script>
    <script src="js/ydui.js"></script>
    <script src="js/vue.min.js"></script>
    <script src="js/vue-resource.js"></script>
    <script src="js/layer/layer.js"></script>
    <script>
        /* 获取头部信息 */
        function GetQueryString(name) {
            var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
            var r = window.location.search.substr(1).match(reg);
            if (r != null) {
                return r[2];
            }
        };

        var app = new Vue({
            el: '#app',
            data: {
                token: GetQueryString('token'),
                checkedIdstr: GetQueryString('checkedId'),
                checkedId: [],
                teamlist: []
            },
            methods: {
                get: function() {
                    this.$http({
                        method: "post",
                        url: "/appTeam/pubgTeamDictList",
                        data: {
                            token: this.token
                        },
                        emulateJSON: true
                    }).then(function(res) { // 访问成功后执行
                        console.log(res.data.data);
                        this.teamlist = res.data.data;
                        this.checkedId = this.checkedIdstr.split(',');

                    }, function(error) { // 访问失败执行
                        console.log(error);
                        layer.msg('接口返回失败');
                        this.loading = false;
                    })
                },
                saveBtn: function() {
                    if (this.checkedNames == "") {
                        layer.msg("请选择战队");
                        return false;
                    }
                    var checkedId;
                    var checkedNamesId = [];
                    var checkedNames = [];
                    for (var i = 0; i < this.checkedId.length; i++) {
                        checkedId = this.checkedId[i];
                        for (var j = 0; j < this.teamlist.length; j++) {
                            if (checkedId == this.teamlist[j].value) {
                                checkedNamesId.push(checkedId);
                                checkedNames.push(this.teamlist[j].label1);
                                break;
                            }
                        }
                    }
                    var returnIds, returnNames;
                    if (checkedNamesId.length > 1) {
                        returnIds = checkedNamesId + ',';
                    } else {
                        returnIds = checkedNamesId[0] + ',';
                    }

                    if (checkedNames.length > 1) {
                        returnNames = checkedNames + ',';
                    } else {
                        returnNames = checkedNames[0] + ',';
                    }

                    if (returnIds.indexOf('undefined') != -1) {
                        layer.msg("请选择一个战队");
                        return;
                    }
                    parent.backteam({
                        'checkedId': returnIds,
                        'checkedNames': returnNames,
                    });
                    var index = parent.layer.getFrameIndex(window.name);
                    parent.layer.close(index);
                }
            },
            mounted: function() {
                this.$nextTick(function() {
                    //初始调用接口
                    this.get();
                })
            }
        })
    </script>
</body>

</html>